package IC.Error;

public class ErrorStack 
{
	public static java.util.Stack<Error> Errors = new java.util.Stack<Error>();
	public static java.util.Stack<Error> Warrnings = new java.util.Stack<Error>();
	public static Error Push(Error e, boolean isWarning)
	{
		return isWarning ? Warrnings.push(e) : Errors.push(e);
	}
	public static Error Push(Error e) { return Push(e, false); }
	
	public static void Initialize()
	{
		Errors.clear();
		Warrnings.clear();
	}
	
	private static void SortStack(java.util.Stack<Error> stack)
	{
		Error[] array = StackToArray(stack);
		java.util.Arrays.sort(array, new Error.ErrorComparer());
		stack.clear();
		AddArrayToStack(stack, array);
	}
	
	private static void AddArrayToStack(java.util.Stack<Error> stack, Error[] array)
	{
		for (Error e : array)
			stack.push(e);
	}
	
	private static Error[] StackToArray (java.util.Stack<Error> stack)
	{
		Error[] ret = new Error[stack.size()];
		int i = 0;
		for (Error e : stack)
			ret[i++] = e;
		return ret;
	}
	
	public static void SortErrorsByLine()
	{
		SortStack(Errors);
		SortStack(Warrnings);
	}
}
